<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: 'nurse-info'
});

import { useCrud, useTable, useUpsert, useSearch } from '@cool-vue/crud';
import { useCool } from '/@/cool';
import { useI18n } from 'vue-i18n';
import { reactive } from 'vue';
import UserSelect from '/$/user/components/user-select.vue';

const { service } = useCool();
const { t } = useI18n();

// 选项
const options = reactive({
	gender: [
		{ label: t('未知'), value: 0 },
		{ label: t('男'), value: 1 },
		{ label: t('女'), value: 2 }
	],
	title: [
		{ label: t('主任护师'), value: 0 },
		{ label: t('副主任护师'), value: 1 },
		{ label: t('主管护师'), value: 2 },
		{ label: t('护师'), value: 3 },
		{ label: t('护士'), value: 4 }
	],
	status: [
		{ label: t('空闲'), value: 0 },
		{ label: t('服务中'), value: 1 },
		{ label: t('已离职'), value: 2 },
	],
});

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: t('姓名'),
			prop: 'name',
			component: { name: 'el-input', props: { clearable: true } },
			span: 12,
			required: true
		},
		{
			label: t('状态'),
			prop: 'status',
			component: { name: 'el-radio', props: { clearable: true } },
			span: 12,
			required: true,
			dict: options.status			
		},
		{
			label: t('工号'),
			prop: 'workNo',
			component: { name: 'el-input', props: { clearable: true } },
			span: 12,
			required: true
		},
		{
			label: t('标签'),
			prop: 'workLabel',
			component: { name: 'el-input-tag', props: { clearable: true } },
			span: 12,
			required: true
		},
		
		{
			label: t('性别'),
			prop: 'gender',
			component: { name: 'el-radio-group', options: options.gender },
			value: 0,
			required: true
		},
		{
			label: t('手机号'),
			prop: 'phone',
			component: { name: 'el-input', props: { clearable: true } },
			span: 12
		},
		{
			label: t('入职日期'),
			prop: 'entryDate',
			component: {
				name: 'el-date-picker',
				props: { type: 'date', valueFormat: 'YYYY-MM-DD' }
			},
			span: 12,
			required: true
		},
		{
			label: t('照片'),
			prop: 'photo',
			component: { name: 'cl-upload' }
		},
		{
			label: t('备注'),
			prop: 'remark',
			component: { name: 'el-input', props: { clearable: true,type:"textarea" } }
		}
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: 'selection' },
		{ label: t('姓名'), prop: 'name', width: 100 },
		{ label: t('工号'), prop: 'workNo', width: 100 },
		{ label: t('状态'), prop: 'status', width:80 },		
		{
			label: t('性别'),
			prop: 'gender',
			minWidth: 120,
			dict: options.gender
		},
		{ label: t('手机号'), prop: 'phone', minWidth: 140 },
		{
			label: t('入职日期'),
			prop: 'entryDate',
			minWidth: 140,
			sortable: 'custom',
			component: {
				name: 'cl-date-text',
				props: { format: 'YYYY-MM-DD' }
			}
		},
		{
			label: t('照片'),
			prop: 'photo',
			minWidth: 100,
			component: { name: 'cl-image', props: { size: 60 } }
		},
		{
			label: t('创建时间'),
			prop: 'createTime',
			minWidth: 170,
			sortable: 'desc',
			component: { name: 'cl-date-text' }
		},
		{
			label: t('更新时间'),
			prop: 'updateTime',
			minWidth: 170,
			sortable: 'custom',
			component: { name: 'cl-date-text' }
		},
		{ type: 'op', buttons: ['edit', 'delete'] }
	]
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.nurse.info
	},
	app => {
		app.refresh();
	}
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
